<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>主号及副号信息维护</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script type="text/javascript" src="/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body">
        <div class="demoTable">
        <xblock>
            <button class="layui-btn" onclick="x_admin_show('新增号码','add')"><i class="layui-icon"></i>新增申请</button>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon" style="line-height:30px">ဂ</i></a>
          </xblock>
        </div>
        <div class="demoTable">
        <div class="layui-inline" >
            <input  id="demoReload_t" name="keyword_t" autocomplete="off" class="layui-input">
          </div>
            <input type="radio" name="keyword_r" id="demoReload_r" value="user_name" checked="">
            <a>姓名</a>
            <input type="radio" name="keyword_r" id="demoReload_r" value="phone_number">
            <a>手机号码</a>
            <input type="radio" name="keyword_r" id="demoReload_r" value="short_number">
            <a>集团短号</a>
          <button class="layui-btn"  data-type="reload" ><i class="layui-icon">&#xe615;</i></button>
      </div> 
      <table class="layui-hide" id="demo" lay-filter="user"></table>
    </div>
    <script type="text/html" id="barDemo">
      <a title="编辑"  lay-event='apply_edit'>
        <i class="layui-icon">&#xe642;</i>
      </a>
      <a title="删除" lay-event='apply_del'>
        <i class="layui-icon">&#xe640;</i>
      </a>
      <a title="报错" lay-event='apply_error'>
          <i class="layui-icon">&#xe702;</i>
        </a>
    </script>
    <script type="text/html" id="toolbarDemo">
    
    </script>
    <script>
      layui.use('table',function(){
        var table = layui.table;
        //执行一个laydate实例
        table.render({
          elem:'#demo',
          method:'post',
          url:'/main_data/',
          cellMinWidth:80,
          toolbar:'#toolbarDemo',
          defaultToolbar:['filter','exports','print'],
          id:'pushReload',
          page:true
          ,cols:[[
            {field:'i_id',title:'ID',sort:true}
            ,{field:'user_company',title:'单位',sort:true}
            ,{field:'user_part__part_name',title:'部门',sort:true}
            ,{field:'user_name',title:'姓名'}
            ,{field:'user_identity',title:'类别',sort:true}
            ,{field:'id_card',title:'身份证号'}
            ,{field:'id_work',title:'工号'}
            ,{field:'user_position',title:'职务',sort:true}
            ,{field:'phone_number',title:'手机号码',sort:true}
            ,{field:'short_number',title:'集团短号',sort:true}
            ,{field:'right',title:'操作',toolbar:"#barDemo"}
          ]]
        });
        table.on('tool(user)',function(obj){
          var data = obj.data;
          if(obj.event === 'apply_edit'){
            layer.open({
              type:2,
              title:'变更',
              shdadeClose: true,
              shade: 0.8,
              area: ['500px','540px'],
              content:'/main_info/alter/'+data.id
            })
          }else if(obj.event === 'apply_del'){
            layer.open({
              type:2,
              title:'删除',
              shdadeClose: true,
              shade: 0.8,
              area: ['500px','540px'],
              content:'/del_main/'+data.id
            });
          }else if(obj.event === 'apply_error'){
            layer.prompt({
              formType:2,
              title:'请输入报错信息',
              area:['200px','100px']
              },function(value,index,elem) {
              var number_id = data.id
              $.ajax({
                cache:false,
                url:'/save_error_main/',
                method:'post',
                dataType:'json',
                data: {'number_id':number_id,'error_content':value},
                async:true,
                success:function(res){
                    if(res.status=='success'){
                        layer.msg(res.msg, {icon: 6},function (index) {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        })
                    }else if(res.status=='fail'){
                        layer.msg(res.msg, {icon: 7},function (index) {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                    },
                    error:function(){
                        layer.msg(res.msg, {icon: 7},function (index) {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                            });
                    }
                });
              });
            };
        });
        var $ = layui.$, active={
          reload:function(){
            var demoReload_t = $('#demoReload_t');
            var demoReload_r = $("input[type='radio']:checked");
            table.reload('pushReload',{
              page:{
                curr:1
              }
              ,where:{
                keyword_t:demoReload_t.val(),
                keyword_r:demoReload_r.val()
              }
            });
          }
        };
        $('.demoTable .layui-btn').on('click',function(){
          var type = $(this).data('type');
          active[type] ? active[type].call(this) : '';
        });
      });
    </script>
  </body>

</html>